





#include "fm33lc0xx_fl.h"
#include "irmp.h"
#include "myuart.h"

IRMP_DATA irmp_data;
int32_t jishuqi;

/**
  * @brief  GPTIM1_TimerBase Initialization function
  * @param  void
  * @retval None
  */
void MF_GPTIM1_TimerBase_Init(void)
{
    FL_GPTIM_InitTypeDef    TimerBase_InitStruct;

    TimerBase_InitStruct.prescaler = ((F_CPU / F_INTERRUPTS)/8) - 1;
    //TimerBase_InitStruct.prescaler = F_CPU/1000000 - 1;
    TimerBase_InitStruct.counterMode = FL_GPTIM_COUNTER_DIR_UP;
    TimerBase_InitStruct.autoReload = 7;
    //TimerBase_InitStruct.autoReload = 1000*300;
    TimerBase_InitStruct.autoReloadState = FL_DISABLE;
    TimerBase_InitStruct.clockDivision = FL_GPTIM_CLK_DIVISION_DIV1;

    FL_GPTIM_Init(GPTIM1, &TimerBase_InitStruct); 

    
    
    
}

/**
  * @brief  GPTIM1 Interrupt Initialization function
  * @param  void
  * @retval None
  */
void MF_GPTIM1_Interrupt_Init(void)
{
    FL_GPTIM_ClearFlag_Update(GPTIM1);
    FL_GPTIM_EnableIT_Update(GPTIM1);  
}



void ledInit()
{
    FL_GPIO_InitTypeDef ledInitstruct;
    ledInitstruct.pin=FL_GPIO_PIN_0;
    ledInitstruct.mode=FL_GPIO_MODE_OUTPUT;
    ledInitstruct.outputType=FL_GPIO_OUTPUT_PUSHPULL;
    ledInitstruct.pull=FL_DISABLE;
    ledInitstruct.remapPin=FL_DISABLE;
    FL_GPIO_Init(GPIOC,&ledInitstruct);
}


void GPTIM1_IRQHandler()
{
    FL_GPTIM_ClearFlag_Update(GPTIM1);
    irmp_ISR();
    //FL_GPIO_ToggleOutputPin(GPIOC,FL_GPIO_PIN_0);
    //jishuqi++;
    //if(jishuqi>15000)
    {
        //FL_GPIO_ToggleOutputPin(GPIOC,FL_GPIO_PIN_0);
        //jishuqi=0;
    }
}


int main()
{
    
    uint8_t irStatus;
    MF_GPTIM1_TimerBase_Init();
    MF_GPTIM1_Interrupt_Init();
    NVIC_EnableIRQ(GPTIM1_IRQn);     
    FL_GPTIM_Enable(GPTIM1);
    ledInit();
    uart5Init();
    irmp_init();
    jishuqi=0;
    uart5_printf("ceshi kaishi \n");
    while(1)
    {
        if (irmp_get_data (&irmp_data))
        {					
            //printf("R: Code: %s",irmp_protocol_names[irmp_data.protocol]);          
            uart5_printf(" Address: 0x%.2X",irmp_data.address);
            uart5_printf(" Command: 0x%.2X",irmp_data.command);
            uart5_printf(" Flags: 0x%.2X\r\n",irmp_data.flags );										
            __NOP();
        }
        irStatus = input(IRMP_PIN);
        if(irStatus)
        {
            FL_GPIO_SetOutputPin(GPIOC,FL_GPIO_PIN_0);
        }
        else
        {
            FL_GPIO_ResetOutputPin(GPIOC,FL_GPIO_PIN_0);
        }
    }
}




